package com.hibase.core.excel.controller;

import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.excel.entity.MdsExcelImportConfigDetail;
import com.hibase.core.excel.service.MdsExcelImportConfigDetailService;
import com.hibase.core.excel.vo.config.detail.*;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Excel模板配置详情管理
 *
 * @author <a href="mailto:xiongliyi@hichain.com">Ian Xiong</a>
 * @since 1.4.50-V2
 */
@AllArgsConstructor
@Api(value = "Excel模板配置详情管理", tags = "Excel模板配置详情管理")
@RequestMapping("/mds-excel-importConfigDetail")
@RestController
public class MdsExcelImportConfigDetailController {

    private final MdsExcelImportConfigDetailService mdsExcelImportConfigDetailService;

    @ApiOperation("分页查询")
    @HibasePostRequestMapping("/list")
    public ResponseModel<MdsExcelImportConfigDetailListVO> queryPage(@RequestBody MdsExcelImportConfigDetailSearchVO searchVO) {
        PageInfo page = mdsExcelImportConfigDetailService.queryPage(searchVO);
        page.setList(EntityUtil.transform(page.getList(), MdsExcelImportConfigDetailListVO.class));
        return ResponseModel.successMsg(page);
    }

    @ApiOperation("新增记录")
    @HibasePostRequestMapping("/save")
    public ResponseModel<String> save(@RequestBody MdsExcelImportConfigDetailInsertVO insertVO) {
        MdsExcelImportConfigDetail entity = EntityUtil.transform(insertVO, MdsExcelImportConfigDetail.class);
        mdsExcelImportConfigDetailService.saveImportConfigDetail(entity);
        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation("更新记录")
    @HibasePostRequestMapping("/update")
    public ResponseModel<String> update(@RequestBody MdsExcelImportConfigDetailUpdateVO updateVO) {
        MdsExcelImportConfigDetail entity = EntityUtil.transform(updateVO, MdsExcelImportConfigDetail.class);
        mdsExcelImportConfigDetailService.updateImportConfigDetail(entity);
        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation("详情查询")
    @HibasePostRequestMapping("/detail")
    public ResponseModel<MdsExcelImportConfigDetailViewVO> detail(@RequestBody OperationIdEntity operationIdEntity) {
        MdsExcelImportConfigDetail entity = mdsExcelImportConfigDetailService.getById(operationIdEntity.getId(), Boolean.TRUE);
        return ResponseModel.successMsg(EntityUtil.transform(entity, MdsExcelImportConfigDetailViewVO.class));
    }
}
